package com.cfjjc.gz.common.util;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 对集合排序的工具类。
 * 
 */
public class OrderTool {

	/**
	 * 对传来的集合根据指定属性排序。
	 * 
	 * @see com.cfjjc.gz.czbs.common.util.BeanComparor
	 * 
	 * @param colleciton
	 *            要排序的集合对象
	 * @param orderBy
	 *            排序依据
	 * @return 排序后的结果
	 */
	public static List sort(Collection collection, String orderBy) {

		List list = (collection instanceof List) ? (List) collection
				: new ArrayList(collection);

		Collections.sort(list, new BeanComparor(orderBy));

		return list;
	}

	public static void main(String[] args) {
		try {
			List list = new ArrayList();
			Map map = new HashMap();
			map.put("REC", "100000");
			list.add(map);
			map = new HashMap();
			map.put("REC", "200000");
			list.add(map);
			map = new HashMap();
			map.put("REC", "300000");
			list.add(map);
			map = new HashMap();
			map.put("REC", "400000");
			list.add(map);
			map = new HashMap();
			map.put("REC", "500000");
			list.add(map);
			map = new HashMap();
			map.put("REC", "600000");
			list.add(map);
			map = new HashMap();
			map.put("REC", "700000");
			list.add(map);
			list = OrderTool.sort(list, "REC");
			System.out.println(list);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}
